function [Population, FrontNo, CrowdDis] = EnvironmentalSelectionW(Vectores, Population, nsort, Point, ro)

%------------------------------- Copyright --------------------------------
% Copyright (c) 2025 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------

    %% Non-dominated sorting
    [FrontNo,MaxFNo] = WASFGASort(Vectores, Population.objs, nsort, Point, ro);
    Next = FrontNo < MaxFNo;

    %% Calculate the crowding distance of each solution
    CrowdDis = CrowdingDistance(Population.objs, FrontNo);

    %% Select the solutions in the last front by their crowding distances
    Last        = find(FrontNo == MaxFNo);
    [~,Rank]    = sort(CrowdDis(Last), 'descend');
    numSelected = min(nsort - sum(Next), numel(Last));  % Avoid selecting more than available
    Next(Last(Rank(1:numSelected))) = true;

    %% Population for next generation
    Population = Population(Next);
    FrontNo    = FrontNo(Next);
    CrowdDis   = CrowdDis(Next);
end